package com.shoppingmall.fragment;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.zyh.toolslib.base.BaseFragment;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.shoppingmall.R;
import com.shoppingmall.activity.home.SearchResultActivity;
import com.shoppingmall.widget.RecycleGridDivider;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * liangwanbo
 */

public class SeachResultGooodFragment extends BaseFragment implements SearchResultActivity.OnModifyListener {


    @BindView(R.id.image_line)
    ImageView imageLine;
    @BindView(R.id.comprehensive)
    TextView comprehensive;
    @BindView(R.id.salenumber)
    TextView salenumber;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.image_money)
    ImageView imageMoney;
    @BindView(R.id.re_money)
    RelativeLayout reMoney;
    @BindView(R.id.tv_choice)
    TextView tvChoice;
    @BindView(R.id.image_choice)
    ImageView imageChoice;
    @BindView(R.id.re_choice)
    RelativeLayout reChoice;
    @BindView(R.id.rv_searchresult_list)
    RecyclerView rvSearchresultList;
    @BindView(R.id.smart_refresh)
    SmartRefreshLayout smartRefresh;
    @BindView(R.id.rv_searchresult_grid_list)
    RecyclerView rvSearchresultGridList;
    @BindView(R.id.re_line)
    RelativeLayout reLine;
    @BindView(R.id.smart_refresh_gride)
    SmartRefreshLayout smartRefreshGride;
    private BaseQuickAdapter<String, BaseViewHolder> mAdapter;
    private BaseQuickAdapter<String, BaseViewHolder> mAdapterporist;
    private boolean isturn = true;//切换

    @Override
    protected void initView(View rootView) {

    }

    @Override
    protected void initData() {
        smartRefreshGride.setVisibility(View.GONE);
        smartRefresh.setVisibility(View.VISIBLE);
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add("");
        }
        mAdapter = new BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_search_result, list) {
            @Override
            protected void convert(@NonNull BaseViewHolder baseViewHolder, String s) {

            }
        };

        rvSearchresultList.setLayoutManager(new GridLayoutManager(getActivity(), 2));
        rvSearchresultList.addItemDecoration(new RecycleGridDivider());
        rvSearchresultList.setAdapter(mAdapter);

        mAdapterporist = new BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_srarchresult_good_portrait, list) {
            @Override
            protected void convert(@NonNull BaseViewHolder baseViewHolder, String s) {

            }
        };
        rvSearchresultGridList.setLayoutManager(new LinearLayoutManager(getActivity()));
        rvSearchresultGridList.addItemDecoration(new RecycleGridDivider());
        rvSearchresultGridList.setAdapter(mAdapterporist);


    }

    @Override
    protected int initLayout() {
        return R.layout.fragment_searchresult_good;
    }

    @Override
    public void modify(String type) {

    }

    @OnClick({R.id.re_line, R.id.comprehensive, R.id.salenumber, R.id.re_money, R.id.re_choice})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.re_line:
                if (isturn == false) {
                    //点击后想要变成什么要的布局样式就搞一个你的需求
                    smartRefreshGride.setVisibility(View.GONE);
                    smartRefresh.setVisibility(View.VISIBLE);
                    //给布尔值重新赋值
                    isturn = true;
                    //给点击按钮的图片重新赋值
                    imageLine.setImageResource(R.drawable.ic_line);
                } else if (isturn == true) {
                    smartRefreshGride.setVisibility(View.VISIBLE);
                    smartRefresh.setVisibility(View.GONE);
                    //给布尔值重新赋值
                    isturn = false;
                    //给点击按钮的图片重新赋值
                    imageLine.setImageResource(R.drawable.ic_list);
                }

                break;
            case R.id.comprehensive:
                break;
            case R.id.salenumber:
                break;
            case R.id.re_money:
                break;
            case R.id.re_choice:
                break;
        }
    }
}
